#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define stoorz_and_QuantAsk using
#define AK namespace
#define IOI_and_Jayun_is_stupid std

stoorz_and_QuantAsk AK IOI_and_Jayun_is_stupid;

const int N = 50;

inline ll Read()
{
	ll x = 0, f = 1;
	char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = -f, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar();
	return x * f;
}

int n;
char s[N];
string a, b;
map <string, int> hsh;

int main()
{
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	n = Read();
	for (int i = 1; i <= n; i++)
	{
		memset (s, 0, sizeof s);
		cin >> a >> b;
		int len = b.size(), dot = 0, mao = 0, num = 0;
		b[len] = '@';
		bool flag = 1;
		for (int j = 0; j < len ; j++)
		{
			s[j] = b[j];
			if ((b[j] == '.' || b[j] == ':') && num == 0 && b[j - 1] != '0') {flag = 0; break;}
			if (b[j] == '.') dot ++, num = 0;
			else
				if (b[j] == ':') mao ++, num = 0;
				else
					if (b[j] >= '1' && b[j] <= '9') num = 1;
			if ((mao && dot < 3) || dot > 3 || mao > 1 || (s[j] == '0' && !num && (b[j + 1] >= '0' && b[j + 1] <= '9')) || b[j] == '-') 
			{flag = 0; break;} 
		}
		if (!flag || dot != 3 || mao != 1 || num == 0) {puts("ERR"); continue;}
		ll A, B, C, D, E;
		sscanf (s, "%lld.%lld.%lld.%lld:%lld", &A, &B, &C, &D, &E);
		if (A > 255 || B > 255 || C > 255 || D > 255 || E > 65535) {puts("ERR"); continue;}
		if (a[0] == 'S')
		{
			if (hsh[b]) {puts("FAIL"); continue;}
			hsh[b] = i; puts("OK");
		} else
		{
			if (hsh[b]) printf ("%d\n", hsh[b]);
			else puts("FAIL");
		}
	}
	return 0;
}

